{extend name="layout" /}
{block name="body"}

<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-body">
                <form name="appinfo">
                    <div class="form-group">
                        <label for="appid">应用id</label>
                        <input type="text" class="form-control" id="appid" name="appid" value="{$appinfo.appid}"
                            disabled>
                    </div>
                    <div class="form-group">
                        <label for="appname">应用名称</label>
                        <input type="text" class="form-control" name="appname" value="{$appinfo.appname}"
                            placeholder="请输入应用名称">
                    </div>
                    <div class="form-group file-group">
                        <label for="appicon">应用图标</label>
                        <div class="input-group">
                            <input type="text" class="form-control file-value" value="{$appinfo.appicon}" name="appicon"
                                value="" placeholder="应用图标" />
                            <input type="file" name="file" accaccept=".png,.jpg,.jpeg,.bmp,.gif" class="hidden"
                                style="display: none;" />
                            <div class="input-group-btn">
                                <button class="btn btn-default file-browser" type="button">上传图片</button>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="introduction">应用简介</label>
                        <textarea class="form-control" aria-label="With textarea" id="introduction" name="introduction"
                            placeholder="请输入应用简介" style="height: 200px;">{$appinfo.introduction}</textarea>
                    </div>
                    <div class="form-group">
                        <label for="author">开发者联系QQ</label>
                        <input type="text" class="form-control" id="author" name="author" value="{$appinfo.author}"
                            placeholder="请输入开发者联系QQ">
                    </div>
                    <div class="form-group">
                        <label for="group">官方群组</label>
                        <input type="text" class="form-control" id="group" name="group" value="{$appinfo.group}"
                            placeholder="请输入官方群组">
                    </div>
                    <div class="form-group">
                        <label for="title">公告标题</label>
                        <input type="text" class="form-control" id="title" name="title" value="{$appinfo.appnotice.title}" placeholder="请输入公告标题">
                        <small class="help-block">改变公告标题以及公告内容其中一项则会新增一条公告内容</small>
                    </div>
                    <div class="form-group">
                        <label for="content">公告内容</label>
                        <textarea class="form-control" aria-label="With textarea" id="content" name="content"
                            placeholder="请输入公告内容" style="height: 200px;">{$appinfo.appnotice.content}</textarea>
                        <small class="help-block">改变公告标题以及公告内容其中一项则会新增一条公告内容</small>
                    </div>
                    <div class="form-group">
                        <label for="version">版本号</label>
                        <input type="text" class="form-control" id="versioncode" name="versioncode" value="{$appinfo.appupdate.versioncode}" placeholder="请输入版本号">
                        <small class="help-block">改变版本号则会新增一条更新信息</small>
                    </div>
                    <div class="form-group">
                        <label for="updatecontent">更新内容</label>
                        <textarea class="form-control" aria-label="With textarea" id="updatecontent" name="updatecontent"
                        placeholder="请输入更新内容" style="height: 200px;">{$appinfo.appupdate.content}</textarea>
                    </div>
                    <div class="form-group">
                        <label for="download">下载地址</label>
                        <input type="text" class="form-control" id="download" name="download" value="{$appinfo.appupdate.download}" placeholder="请输入下载地址">
                    </div>
                    <div class="form-group">
                        <label for="grade">等级划分</label>
                        <textarea class="form-control" aria-label="With textarea" id="grade" name="grade"
                            placeholder="必须按照给的格式输入" style="height: 200px;">{$appinfo.grade}</textarea>
                    </div>
                    <div class="form-group">
                        <label for="zc_money">注册赠送金币</label>
                        <input type="text" class="form-control" id="zc_money" name="zc_money"
                            value="{$appinfo.zc_money}" placeholder="请输入注册赠送金币">
                    </div>
                    <div class="form-group">
                        <label for="zc_exp">注册赠送经验</label>
                        <input type="text" class="form-control" id="zc_exp" name="zc_exp" value="{$appinfo.zc_exp}"
                            placeholder="请输入注册赠送经验">
                    </div>
                    <div class="form-group">
                        <label for="zc_vip">注册赠送会员天数</label>
                        <input type="text" class="form-control" id="zc_vip" name="zc_vip" value="{$appinfo.zc_vip}"
                            placeholder="请输入注册赠送会员天数">
                    </div>
                    <div class="form-group">
                        <label for="sign_money">签到赠送金币</label>
                        <input type="text" class="form-control" id="sign_money" name="sign_money"
                            value="{$appinfo.sign_money}" placeholder="请输入签到赠送金币">
                    </div>
                    <div class="form-group">
                        <label for="sign_exp">签到赠送经验</label>
                        <input type="text" class="form-control" id="sign_exp" name="sign_exp"
                            value="{$appinfo.sign_exp}" placeholder="请输入签到赠送经验">
                    </div>
                    <div class="form-group">
                        <label for="sign_vip">签到赠送会员天数</label>
                        <input type="text" class="form-control" id="sign_vip" name="sign_vip"
                            value="{$appinfo.sign_vip}" placeholder="请输入签到赠送会员天数">
                    </div>
                    <div class="form-group">
                        <label for="invitation_money">邀请人获得金币</label>
                        <input type="text" class="form-control" id="invitation_money" name="invitation_money"
                            value="{$appinfo.invitation_money}" placeholder="请输入邀请者获得金币">
                    </div>
                    <div class="form-group">
                        <label for="invitation_exp">邀请人获得经验</label>
                        <input type="text" class="form-control" id="invitation_exp" name="invitation_exp"
                            value="{$appinfo.invitation_exp}" placeholder="请输入邀请者获得经验">
                    </div>
                    <div class="form-group">
                        <label for="invitation_vip">邀请人获得vip天数</label>
                        <input type="text" class="form-control" id="invitation_vip" name="invitation_vip"
                            value="{$appinfo.invitation_vip}" placeholder="请输入邀请者获得vip天数">
                    </div>
                    <div class="form-group">
                        <label for="equipment_num">单设备注册上限0代表无限</label>
                        <input type="devicenum" class="form-control" id="equipment_num" name="equipment_num" value="{$appinfo.equipment_num}"
                            placeholder="限制数量">
                    </div>
                    <div class="form-group">
                        <label for="is_login">是否允许登录</label>
                        <div class="custom-control custom-switch">
                            {if $appinfo.is_login == 0}
                            <input type="checkbox" class="custom-control-input" id="is_login" value="0" name="is_login"
                                checked>
                            {else /}
                            <input type="checkbox" class="custom-control-input" id="is_login" value="1" name="is_login">
                            {/if}
                            <label class="custom-control-label" for="is_login"></label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="is_reg">是否允许注册</label>
                        <div class="custom-control custom-switch">
                            {if $appinfo.is_reg == 0}
                            <input type="checkbox" class="custom-control-input" id="is_reg" value="0" name="is_reg"
                                checked>
                            {else /}
                            <input type="checkbox" class="custom-control-input" id="is_reg" value="1" name="is_reg">
                            {/if}
                            <label class="custom-control-label" for="is_reg"></label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="is_regemailcode">注册是否需要验证码</label>
                        <div class="custom-control custom-switch">
                            {if $appinfo.is_regemailcode == 0}
                            <input type="checkbox" class="custom-control-input" id="is_regemailcode" value="0" name="is_regemailcode"
                                checked onchange="is_codetype()">
                            {else /}
                            <input type="checkbox" class="custom-control-input" id="is_regemailcode" value="1" name="is_regemailcode" onchange="is_codetype()">
                            {/if}
                            <label class="custom-control-label" for="is_regemailcode"></label>
                        </div>
                    </div>
                    <div class="form-group" id="codetypeshow" {if $appinfo.is_regemailcode == 1} style="display: none;" {/if}>
                        <label for="codetype">验证码发送通道</label>
                        <select class="form-control" id="codetype" name="codetype">
                            <option value="0" {if $appinfo.codetype == 0} selected {/if}>邮箱发送</option>
                            <option value="1" {if $appinfo.codetype == 1} selected {/if}>阿里云短信发送</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="is_equipment">是否允许新设备登录账号</label>
                        <div class="custom-control custom-switch">
                            {if $appinfo.is_equipment == 0}
                            <input type="checkbox" class="custom-control-input" id="is_equipment" value="0"
                                name="is_equipment" checked>
                            {else /}
                            <input type="checkbox" class="custom-control-input" id="is_equipment" value="1"
                                name="is_equipment">
                            {/if}
                            <label class="custom-control-label" for="is_equipment"></label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="is_remoteLogin">是否启用异地登录发邮件</label>
                        <div class="custom-control custom-switch">
                            {if $appinfo.is_remoteLogin == 0}
                            <input type="checkbox" class="custom-control-input" id="is_remoteLogin" value="0"
                                name="is_remoteLogin" checked>
                            {else /}
                            <input type="checkbox" class="custom-control-input" id="is_remoteLogin" value="1"
                                name="is_remoteLogin">
                            {/if}
                            <label class="custom-control-label" for="is_remoteLogin"></label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="is_sign">是否启用加密</label>
                        <div class="custom-control custom-switch">
                            {if $appinfo.is_sign == 0}
                            <input type="checkbox" class="custom-control-input" id="is_sign" value="0" name="is_sign" checked onchange="is_signkey()">
                            {else /}
                            <input type="checkbox" class="custom-control-input" id="is_sign" value="1" name="is_sign" onchange="is_signkey()">
                            {/if}
                            <label class="custom-control-label" for="is_sign"></label>
                        </div>
                        <small>采用AES-128-ECB加密</small>
                    </div>
                    <div class="form-group" id="signkeyshow" {if $appinfo.is_sign == 1} style="display: none;" {/if}>
                        <label for="signkey">key</label>
                        <div class="input-group">
                            <input type="text" class="form-control" id="signkey" name="signkey"
                                value="{$appinfo.signkey}" placeholder="签名key">
                            <div class="input-group-append">
                                <span style="cursor: pointer;" class="input-group-text"
                                    onclick="javascript:document.getElementById('signkey').value=randomString(16);">生成</span>
                            </div>
                        </div>
                        <small>key值必须16位,推荐大家直接生成</small>
                    </div>
                    <div class="form-group">
                        <label for="poststate">帖子是否需要审核</label>
                        <div class="custom-control custom-switch">
                            {if $appinfo.poststate == 0}
                            <input type="checkbox" class="custom-control-input" id="poststate" value="0" name="poststate"
                                checked>
                            {else /}
                            <input type="checkbox" class="custom-control-input" id="poststate" value="1" name="poststate">
                            {/if}
                            <label class="custom-control-label" for="poststate"></label>
                        </div>
                        <small class="help-block">关闭后发帖则会直接通过</small>
                    </div>
                    <div class="form-group">
                        <label for="is_state">是否开启app</label>
                        <div class="custom-control custom-switch">
                            {if $appinfo.is_state == 0}
                            <input type="checkbox" class="custom-control-input" id="is_state" value="0" name="is_state"
                                checked>
                            {else /}
                            <input type="checkbox" class="custom-control-input" id="is_state" value="1" name="is_state">
                            {/if}
                            <label class="custom-control-label" for="is_state"></label>
                        </div>
                        <small class="help-block">app关闭后将不能进行任何操作，接口功能全部失效</small>
                    </div>
                    <button type="button" onclick="updateapp()" class="btn btn-w-sm btn-primary mb-2">提交</button>
                    <button type="button" class="btn btn-default mb-2"
                        onclick="javascript:history.back(-1);return false;">返 回
                    </button>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    function updateapp() {
        var l = $('body').lyearloading({
            opacity: 0.2,
            spinnerSize: 'lg'
        });
        //移除属性
        $("#appid").removeAttr("disabled");
        $.ajax({
            url: "{:url('app/edit')}",
            type: 'post',
            data: $("form").serializeArray(),
            dataType: 'json',
            success: function (data) {
                l.destroy();
                $("#appid").attr("disabled", "true");
                if (data.code == 1) {
                    // notify.success(data.msg, function () {
                    //     location.href = data.url;
                    // }, 1000);
                } else {
                    $("#captcha").click();
                    notify.error(data.msg);
                }
            },
            error: function () {
                l.destroy();
                $("#appid").attr("disabled", "true");
                notify.error("服务器错误");
            }
        })
        return false;
    }

    function is_signkey() {
        var is_sign = $("#is_sign").prop("checked");
        if(is_sign){
            $("#signkeyshow").show();
        }else{
            $("#signkeyshow").hide();
        }
    }

    function is_codetype() {
        var is_regemailcode = $("#is_regemailcode").prop("checked");
        if(is_regemailcode){
            $("#codetypeshow").show();
        }else{
            $("#codetypeshow").hide();
        }
    }
</script>
{/block}